<template>
  <div>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        prop="id"
        label="ID"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="电话"
        width="180">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱"
        width="180">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>
    </el-table>
    <el-pagination
      align="right"
      layout="prev, pager, next"
      :page-size="pageSize"
      :current-page="currentPage"
      @current-change="getPage"
      :total="totals">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'Mytable2',
  data () {
    return {
      pageSize:5,
      currentPage:1,
      totals:0,
      tableData: []
    }
  },
  methods:{
    getPage(curr){
      this.currentPage = curr;
      //请求后端接口
      this.sendRequest()
    },
    //请求后端接口
    sendRequest(){
      let para = {"currentPage":this.currentPage,"pageSize":this.pageSize}
      this.$http.post("/user/list",para)
        .then(result=>{
          //回调函数，接收后端返回的数据
          this.tableData = result.data.data;
          this.totals = result.data.totals;
        })
        .catch(reason => {
          alert("网络不通...")
        })
    }
  },
  //钩子函数：在页面加载之前执行
  mounted() {
    this.sendRequest()
  }
}
</script>


